<?php

namespace app\api\controller\public;
use app\common\service\Result;
use app\shop\model\app\AppContent;
use app\shop\model\settings\Setting;
/**
 * 公司介绍
 */
class App
{
    /**
     * 轮播图
     */
    public function banner()
    {
        $app_id = request()->app_id;
        $map = [
            'app_id' => $app_id,
            'position' => AppContent::POSITION_BANNER,
        ];
        $data = AppContent::where($map)->order('sort desc')->select();
        return Result::success($data ?? []);
    }

    /**
     * 图片导航
     */
    public function picNav()
    {
        $app_id = request()->app_id;
        $map = [
            'app_id' => $app_id,
            'position' => AppContent::POSITION_NAV,
        ];
        $data = AppContent::where($map)->order('sort desc')->select();
        return Result::success($data ?? []);
    }

    //获取商城设置信息
    public function setting()
    {
        $app_id = request()->app_id;
        $keys = input('keys') ?? [];
        if (!is_array($keys)) {
            $keys = explode(',', $keys);
        }
        if (!in_array('store', $keys)) {
            $keys[] = 'store';
        }
        $result = [];
        foreach ($keys as $key) {
            $result[$key] = Setting::getItem($key, $app_id);
        }
        return Result::success($result);
    }
}